#!/usr/bin/env ruby

class DefaultFilter
    def process(data)
        #printf(">>DefaultFilter:%s", data)
    end
end

class MethodCallFilter < DefaultFilter
    
    def initialize(expression, destination_file)
        @match_expression = expression
    end
    
    def process(data)
        if data =~ @match_expression
            printf(">>MethodCallFilter:%s", data)
        end
    end
end

class ThirdPartyCallFilter < DefaultFilter
    def process(data)
        #printf(">>ThirdPartyCallFilter:%s", data)
    end
end

class LogParser
    
    def initialize(log_file)
        @file_name = log_file
        @filters = []
    end
    
    def add_filter(filter)
        @filters.add(filter)
    end
    
    def process_filters()
        File.open("log.txt").each do |line|
            @filters.each do |filter|
                filter.process(line)
            end
        end
    end
end

puts "Processing log.txt"
log_parser = LogParser.new('log.txt')
log_parser.add_filter(DefaultFilter.new)
log_parser.add_filter(MethodCallFilter.new(/START/, 'method_call.csv'))
log_parser.add_filter(ThirdPartyCallFilter.new)
log_parser.process_filters()